package com.sfzd5.mistakesbook;

import android.content.Context;
import android.content.DialogInterface;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

public class InputTextDialog {

    Context context;

    public InputTextDialog(Context context){
        this.context = context;
    }

    public void showInputDialog(String title, InputTextDialogResultInterface resultInterface) {
        /*@setView 装入一个EditView
         */
        final EditText editText = new EditText(context);
        AlertDialog.Builder inputDialog =
                new AlertDialog.Builder(context);
        inputDialog.setTitle(title).setView(editText);
        inputDialog.setPositiveButton("确定",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String result = editText.getText().toString();
                        resultInterface.result(result);
                    }
                }).setNegativeButton("关闭",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //...To-do
                    }
                });
        inputDialog.show();
    }
}
